<?php 
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
    #CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: m_vendor Model
	+ Description	: For record model process back-end
	+ Filename 		: c_m_vendor.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 11:40:14

*/

class M_m_vendor extends CI_Model{

		//constructor
		function __construct() {
			parent::__construct();
		}
		
		function get_div(){
			$sql = "SELECT div_id, div_name FROM m_div";
			
			$result = $this->db->query($sql);
			$nbrows = $result->num_rows();
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}

		//function for get list record
		function m_vendor_list($filter,$start,$end){
		
			$sql = "call prepare_tablesplit";
			$this->db->query($sql);
			$sql = "SELECT vendor_id, vendor_name, m_div_id FROM m_vendor";
			$query = $this->db->query($sql);
			foreach($query->result()  as $result){
				$sql = "call split_string('".$result->m_div_id."',',',".$result->vendor_id.");";
				$this->db->query($sql);
			}
			
			$sql = "SELECT * FROM (SELECT vendor_id,
							group_concat(div_name) as div_name,
						   vendor_kode,
						   vendor_name,
						   vendor_type,
						   vendor_address,
						   vendor_phone,
						   vendor_fax,
						   vendor_email,
						   vendor_cp,
						   vendor_dir,
						   vendor_dirpos,
						   vendor_rek,
						   vendor_bank,
						   vendor_bankowner,
						   vendor_cert,
						   vendor_npwp,
						   vendor_certdate,
						   IF(DATE_FORMAT(vendor_certdate,'%Y-%m-%d')='0000-00-00','',vendor_certdate) AS vendor_certdate_str,
						   vendor_active,
						   vendor_created_date,
						   vendor_created_by,
						   vendor_updated_date,
						   vendor_updated_by,
						   vendor_updated_count,
						   m_div_id
					FROM m_vendor
					LEFT JOIN splitResults ON (vendor_id = split_id) 
					LEFT JOIN m_div ON(m_div.div_id = splitResults.split_value)
					GROUP BY vendor_id) t 
					";

			// For simple search
			if ($filter<>""){
				$sql .=preg_match("/WHERE/i",$sql)? " AND ":" WHERE ";
				$sql .= " (lower(vendor_kode) LIKE '%".addslashes(strtolower($filter))."%'  OR
							lower(vendor_name) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_address) LIKE '%".addslashes(strtolower($filter))."%' OR
						   lower(vendor_phone) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_fax) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_email) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_cp) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_dir) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_bankowner) LIKE '%".addslashes(strtolower($filter))."%'  OR
						   lower(vendor_npwp) LIKE '%".addslashes(strtolower($filter))."%' 
						   )";
			}

			$result = $this->db->query($sql);
			$nbrows = $result->num_rows();
			$limit = $sql." LIMIT ".$start.", ".$end;
			$result = $this->db->query($limit);

			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}

		//function for create new record
		function m_vendor_create(
				 $vendor_kode,
				 $vendor_name,
				 $vendor_type,
				 $vendor_address,
				 $vendor_phone,
				 $vendor_fax,
				 $vendor_email,
				 $vendor_cp,
				 $vendor_dir,
				 $vendor_dirpos,
				 $vendor_rek,
				 $vendor_bank,
				 $vendor_bankowner,
				 $vendor_cert,
				 $vendor_certdate,
				 $vendor_active,
				 $vendor_created_date,
				 $vendor_created_by,
				 $vendor_updated_date,
				 $vendor_updated_by,
				 $vendor_updated_count,
				 $m_div_id,$vendor_npwp){
			$data = array(
						 "vendor_kode"=>$vendor_kode,
						 "vendor_name"=>$vendor_name,
						 "vendor_type"=>$vendor_type,
						 "vendor_address"=>$vendor_address,
						 "vendor_phone"=>$vendor_phone,
						 "vendor_fax"=>$vendor_fax,
						 "vendor_email"=>$vendor_email,
						 "vendor_cp"=>$vendor_cp,
						 "vendor_dir"=>$vendor_dir,
						 "vendor_dirpos"=>$vendor_dirpos,
						 "vendor_rek"=>$vendor_rek,
						 "vendor_bank"=>$vendor_bank,
						 "vendor_bankowner"=>$vendor_bankowner,
						 "vendor_cert"=>$vendor_cert,
						 "vendor_npwp"=>$vendor_npwp,
						 "vendor_certdate"=>$vendor_certdate,
						 "vendor_active"=>$vendor_active,
						 "vendor_created_date"=>$vendor_created_date,
						 "vendor_created_by"=>$vendor_created_by,
						 "vendor_updated_date"=>$vendor_updated_date,
						 "vendor_updated_by"=>$vendor_updated_by,
						 "vendor_updated_count"=>$vendor_updated_count,
						 "m_div_id"=>$m_div_id					);
			$this->db->insert('m_vendor', $data);
			if($this->db->affected_rows())
				return '1';
			else
				return '0';
		}

		//function for update record
		function m_vendor_update($vendor_id,
				 $vendor_kode,
				 $vendor_name,
				 $vendor_type,
				 $vendor_address,
				 $vendor_phone,
				 $vendor_fax,
				 $vendor_email,
				 $vendor_cp,
				 $vendor_dir,
				 $vendor_dirpos,
				 $vendor_rek,
				 $vendor_bank,
				 $vendor_bankowner,
				 $vendor_cert,
				 $vendor_certdate,
				 $vendor_active,
				 $vendor_created_date,
				 $vendor_created_by,
				 $vendor_updated_date,
				 $vendor_updated_by,
				 $vendor_updated_count,
				 $m_div_id,$vendor_npwp){
			$data = array(
						"vendor_kode"=>$vendor_kode,
						"vendor_name"=>$vendor_name,
						"vendor_type"=>$vendor_type,
						"vendor_address"=>$vendor_address,
						"vendor_phone"=>$vendor_phone,
						"vendor_fax"=>$vendor_fax,
						"vendor_email"=>$vendor_email,
						"vendor_cp"=>$vendor_cp,
						"vendor_dir"=>$vendor_dir,
						"vendor_dirpos"=>$vendor_dirpos,
						"vendor_rek"=>$vendor_rek,
						"vendor_bank"=>$vendor_bank,
						"vendor_bankowner"=>$vendor_bankowner,
						"vendor_cert"=>$vendor_cert,
						"vendor_npwp"=>$vendor_npwp,
						"vendor_certdate"=>$vendor_certdate,
						"vendor_active"=>$vendor_active,
						"vendor_created_date"=>$vendor_created_date,
						"vendor_created_by"=>$vendor_created_by,
						"vendor_updated_date"=>$vendor_updated_date,
						"vendor_updated_by"=>$vendor_updated_by,
						"vendor_updated_count"=>$vendor_updated_count,
						"m_div_id"=>$m_div_id					
						);


			$this->db->where('vendor_id', $vendor_id);
			$this->db->update('m_vendor', $data);
			return '1';
		}

		//fcuntion for delete record
		function m_vendor_delete($pkid){
			// You could do some checkups here and return '0' or other error consts.
			// Make a single query to delete all of the m_vendors at the same time :
			if(sizeof($pkid)<1){
				return '0';
			} else if (sizeof($pkid) == 1){
				$sql = "DELETE FROM m_vendor WHERE vendor_id = ".$pkid[0];
				$this->db->query($sql);
			} else {
				$sql = "DELETE FROM m_vendor WHERE ";
				for($i = 0; $i < sizeof($pkid); $i++){
					$sql = $sql . "vendor_id= ".$pkid[$i];
					if($i<sizeof($pkid)-1){
						$sql = $sql . " OR ";
					}
				}
				$this->db->query($sql);
			}
			if($this->db->affected_rows()>0)
				return '1';
			else
				return '0';
		}

		//function for advanced search record
		function m_vendor_search($vendor_id,
				 $vendor_name,
				 $vendor_type,
				 $vendor_address,
				 $vendor_phone,
				 $vendor_fax,
				 $vendor_email,
				 $vendor_cp,
				 $vendor_dir,
				 $vendor_dirpos,
				 $vendor_rek,
				 $vendor_bank,
				 $vendor_bankowner,
				 $vendor_cert,
				 $vendor_certdate,
				 $vendor_active,
				 $vendor_created_date,
				 $vendor_created_by,
				 $vendor_updated_date,
				 $vendor_updated_by,
				 $vendor_updated_count,
				 $m_div_id,$start,$end){
			//full query
			$sql = "SELECT vendor_id,
						   vendor_name,
						   vendor_type,
						   vendor_address,
						   vendor_phone,
						   vendor_fax,
						   vendor_email,
						   vendor_cp,
						   vendor_dir,
						   vendor_dirpos,
						   vendor_rek,
						   vendor_bank,
						   vendor_bankowner,
						   vendor_cert,
						   vendor_certdate,
						   vendor_active,
						   vendor_created_date,
						   vendor_created_by,
						   vendor_updated_date,
						   vendor_updated_by,
						   vendor_updated_count,
						   m_div_id
					FROM   m_vendor";

			/* if($vendor_id!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_id) LIKE '%".addslashes(strtolower($vendor_id))."%'";
			}; */
			if($vendor_name!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_name) LIKE '%".addslashes(strtolower($vendor_name))."%'";
			};
			if($vendor_type!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_type) LIKE '%".addslashes(strtolower($vendor_type))."%'";
			};
			if($vendor_address!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_address) LIKE '%".addslashes(strtolower($vendor_address))."%'";
			};
			if($vendor_phone!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_phone) LIKE '%".addslashes(strtolower($vendor_phone))."%'";
			};
			if($vendor_fax!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_fax) LIKE '%".addslashes(strtolower($vendor_fax))."%'";
			};
			if($vendor_email!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_email) LIKE '%".addslashes(strtolower($vendor_email))."%'";
			};
			if($vendor_cp!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_cp) LIKE '%".addslashes(strtolower($vendor_cp))."%'";
			};
			if($vendor_dir!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_dir) LIKE '%".addslashes(strtolower($vendor_dir))."%'";
			};
			if($vendor_dirpos!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_dirpos) LIKE '%".addslashes(strtolower($vendor_dirpos))."%'";
			};
			if($vendor_rek!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_rek) LIKE '%".addslashes(strtolower($vendor_rek))."%'";
			};
			if($vendor_bank!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_bank) LIKE '%".addslashes(strtolower($vendor_bank))."%'";
			};
			if($vendor_bankowner!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_bankowner) LIKE '%".addslashes(strtolower($vendor_bankowner))."%'";
			};
			if($vendor_cert!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_cert) LIKE '%".addslashes(strtolower($vendor_cert))."%'";
			};
			if($vendor_certdate!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_certdate) LIKE '%".addslashes(strtolower($vendor_certdate))."%'";
			};
			/* if($vendor_active!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_active) LIKE '%".addslashes(strtolower($vendor_active))."%'";
			};
			if($vendor_created_date!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_created_date) LIKE '%".addslashes(strtolower($vendor_created_date))."%'";
			};
			if($vendor_created_by!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_created_by) LIKE '%".addslashes(strtolower($vendor_created_by))."%'";
			};
			if($vendor_updated_date!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_updated_date) LIKE '%".addslashes(strtolower($vendor_updated_date))."%'";
			};
			if($vendor_updated_by!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_updated_by) LIKE '%".addslashes(strtolower($vendor_updated_by))."%'";
			};
			if($vendor_updated_count!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(vendor_updated_count) LIKE '%".addslashes(strtolower($vendor_updated_count))."%'";
			}; */
			if($m_div_id!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(m_div_id) LIKE '%".addslashes(strtolower($m_div_id))."%'";
			};

			$result = $this->db->query($sql);
			$nbrows = $result->num_rows();
			$limit = $sql." LIMIT ".$start.",".$end;
			$result = $this->db->query($limit);

			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}

		//function for print record
		function m_vendor_print($vendor_id,
				 $vendor_name,
				 $vendor_type,
				 $vendor_address,
				 $vendor_phone,
				 $vendor_fax,
				 $vendor_email,
				 $vendor_cp,
				 $vendor_dir,
				 $vendor_dirpos,
				 $vendor_rek,
				 $vendor_bank,
				 $vendor_bankowner,
				 $vendor_cert,
				 $vendor_certdate,
				 $vendor_active,
				 $vendor_created_date,
				 $vendor_created_by,
				 $vendor_updated_date,
				 $vendor_updated_by,
				 $vendor_updated_count,
				 $m_div_id,$option,$filter){
			//full query
			$sql = "SELECT vendor_id,
						   vendor_kode,
						   vendor_name,
						   vendor_type,
						   vendor_address,
						   vendor_phone,
						   vendor_fax,
						   vendor_email,
						   vendor_cp,
						   vendor_dir,
						   vendor_dirpos,
						   vendor_rek,
						   vendor_bank,
						   vendor_bankowner,
						   vendor_cert,
						   vendor_certdate,
						   vendor_active,
						   vendor_created_date,
						   vendor_created_by,
						   vendor_updated_date,
						   vendor_updated_by,
						   vendor_updated_count,
						   vendor_npwp,
						   m_div_id,
						   div_name
				    FROM   m_vendor
					LEFT JOIN m_div ON m_div_id = div_id
					";

			if($option=='LIST'){
				$sql .=preg_match("/WHERE/i",$sql)? " AND ":" WHERE ";
				$sql .= " (lower(vendor_name) LIKE '%".addslashes(strtolower($filter))."%' OR lower(vendor_address) LIKE '%".addslashes(strtolower($filter))."%' )";
			} else if($option=='SEARCH'){
				/* if($vendor_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_id) LIKE '%".addslashes(strtolower($vendor_id))."%'";
				}; */
				if($vendor_name!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_name) LIKE '%".addslashes(strtolower($vendor_name))."%'";
				};
				if($vendor_type!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_type) LIKE '%".addslashes(strtolower($vendor_type))."%'";
				};
				if($vendor_address!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_address) LIKE '%".addslashes(strtolower($vendor_address))."%'";
				};
				if($vendor_phone!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_phone) LIKE '%".addslashes(strtolower($vendor_phone))."%'";
				};
				if($vendor_fax!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_fax) LIKE '%".addslashes(strtolower($vendor_fax))."%'";
				};
				if($vendor_email!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_email) LIKE '%".addslashes(strtolower($vendor_email))."%'";
				};
				if($vendor_cp!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_cp) LIKE '%".addslashes(strtolower($vendor_cp))."%'";
				};
				if($vendor_dir!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_dir) LIKE '%".addslashes(strtolower($vendor_dir))."%'";
				};
				if($vendor_dirpos!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_dirpos) LIKE '%".addslashes(strtolower($vendor_dirpos))."%'";
				};
				if($vendor_rek!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_rek) LIKE '%".addslashes(strtolower($vendor_rek))."%'";
				};
				if($vendor_bank!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_bank) LIKE '%".addslashes(strtolower($vendor_bank))."%'";
				};
				if($vendor_bankowner!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_bankowner) LIKE '%".addslashes(strtolower($vendor_bankowner))."%'";
				};
				if($vendor_cert!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_cert) LIKE '%".addslashes(strtolower($vendor_cert))."%'";
				};
				if($vendor_certdate!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_certdate) LIKE '%".addslashes(strtolower($vendor_certdate))."%'";
				};
				if($vendor_active!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_active) LIKE '%".addslashes(strtolower($vendor_active))."%'";
				};
				/* if($vendor_created_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_created_date) LIKE '%".addslashes(strtolower($vendor_created_date))."%'";
				};
				if($vendor_created_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_created_by) LIKE '%".addslashes(strtolower($vendor_created_by))."%'";
				};
				if($vendor_updated_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_date) LIKE '%".addslashes(strtolower($vendor_updated_date))."%'";
				};
				if($vendor_updated_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_by) LIKE '%".addslashes(strtolower($vendor_updated_by))."%'";
				};
				if($vendor_updated_count!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_count) LIKE '%".addslashes(strtolower($vendor_updated_count))."%'";
				}; */
				if($m_div_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(m_div_id) LIKE '%".addslashes(strtolower($m_div_id))."%'";
				};
			}
			$query = $this->db->query($sql);
			return $query->result();
		}

		//function  for export to excel
		function m_vendor_export_excel($vendor_id ,$vendor_name ,$vendor_type ,$vendor_address ,$vendor_phone ,$vendor_fax ,$vendor_email ,$vendor_cp ,$vendor_dir ,$vendor_dirpos ,$vendor_rek ,$vendor_bank ,$vendor_bankowner ,$vendor_cert ,$vendor_certdate ,$vendor_active ,$vendor_created_date ,$vendor_created_by ,$vendor_updated_date ,$vendor_updated_by ,$vendor_updated_count ,$m_div_id ,$option,$filter){
			//full query
			$sql = "SELECT vendor_id,
						   vendor_kode,
						   vendor_name,
						   vendor_type,
						   vendor_address,
						   vendor_phone,
						   vendor_fax,
						   vendor_email,
						   vendor_cp,
						   vendor_dir,
						   vendor_dirpos,
						   vendor_rek,
						   vendor_bank,
						   vendor_bankowner,
						   vendor_cert,
						   vendor_certdate,
						   vendor_active,
						   vendor_created_date,
						   vendor_created_by,
						   vendor_updated_date,
						   vendor_updated_by,
						   vendor_updated_count,
						   vendor_npwp,
						   m_div_id,
						   div_name
				    FROM m_vendor
					LEFT JOIN m_div ON m_div_id = div_id";

			if($option=='LIST'){
				$sql .=preg_match("/WHERE/i",$sql)? " AND ":" WHERE ";
				$sql .= "(lower(vendor_name) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(vendor_address) LIKE '%".addslashes(strtolower($filter))."%' )";
			} else if($option=='SEARCH'){
				/* if($vendor_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_id) LIKE '%".addslashes(strtolower($vendor_id))."%'";
				}; */
				if($vendor_name!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_name) LIKE '%".addslashes(strtolower($vendor_name))."%'";
				};
				if($vendor_type!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_type) LIKE '%".addslashes(strtolower($vendor_type))."%'";
				};
				if($vendor_address!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_address) LIKE '%".addslashes(strtolower($vendor_address))."%'";
				};
				if($vendor_phone!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_phone) LIKE '%".addslashes(strtolower($vendor_phone))."%'";
				};
				if($vendor_fax!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_fax) LIKE '%".addslashes(strtolower($vendor_fax))."%'";
				};
				if($vendor_email!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_email) LIKE '%".addslashes(strtolower($vendor_email))."%'";
				};
				if($vendor_cp!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_cp) LIKE '%".addslashes(strtolower($vendor_cp))."%'";
				};
				if($vendor_dir!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_dir) LIKE '%".addslashes(strtolower($vendor_dir))."%'";
				};
				if($vendor_dirpos!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_dirpos) LIKE '%".addslashes(strtolower($vendor_dirpos))."%'";
				};
				if($vendor_rek!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_rek) LIKE '%".addslashes(strtolower($vendor_rek))."%'";
				};
				if($vendor_bank!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_bank) LIKE '%".addslashes(strtolower($vendor_bank))."%'";
				};
				if($vendor_bankowner!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_bankowner) LIKE '%".addslashes(strtolower($vendor_bankowner))."%'";
				};
				if($vendor_cert!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_cert) LIKE '%".addslashes(strtolower($vendor_cert))."%'";
				};
				if($vendor_certdate!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_certdate) LIKE '%".addslashes(strtolower($vendor_certdate))."%'";
				};
				/* if($vendor_active!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_active) LIKE '%".addslashes(strtolower($vendor_active))."%'";
				};
				if($vendor_created_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_created_date) LIKE '%".addslashes(strtolower($vendor_created_date))."%'";
				};
				if($vendor_created_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_created_by) LIKE '%".addslashes(strtolower($vendor_created_by))."%'";
				};
				if($vendor_updated_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_date) LIKE '%".addslashes(strtolower($vendor_updated_date))."%'";
				};
				if($vendor_updated_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_by) LIKE '%".addslashes(strtolower($vendor_updated_by))."%'";
				};
				if($vendor_updated_count!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(vendor_updated_count) LIKE '%".addslashes(strtolower($vendor_updated_count))."%'";
				}; */
				if($m_div_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(m_div_id) LIKE '%".addslashes(strtolower($m_div_id))."%'";
				};
			}
			$query = $this->db->query($sql);
			return $sql;
		}

}
?>